package com.wlr.study.leetcode;

/**
 * 删除第K个节点
 */
public class LeetCode19 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0);
        dummy.next=head;
        ListNode fast = head;
        ListNode low = dummy;
        int step = n - 1;
        if (head == null || n <= 0) {
            return null;
        }
        for (int i = 0; i < step; i++) {
            fast = fast.next;
        }
        while (fast.next != null) {
            fast = fast.next;
            low = low.next;
        }
        low.next = low.next.next;

        return dummy.next;
    }
}
